package com.github.lzyzsd.circleprogress;

import ohos.global.resource.ResourceManager;

public final class Utils {
    private final static float NORMAL_PIXEL_DENSITY = 160f;

    private Utils() {
    }

    //todo change function name to "fp2px"
    public static int dp2px(ResourceManager resourceManager, float dp) {
        float scale = resourceManager.getDeviceCapability().screenDensity;
        return (int) (dp * scale / NORMAL_PIXEL_DENSITY + 0.5f);
        /*
        final float scale = resourceManager.getDeviceCapability().screenDensity;
        return  (int)(dp * scale + 0.5f);
         */
    }

    public static int sp2px(ResourceManager resourceManager, float sp) {
        float scale = resourceManager.getDeviceCapability().screenDensity;
        return (int) (sp * scale / NORMAL_PIXEL_DENSITY + 0.5f);
        /*
        final float scale = resourceManager.getDeviceCapability().screenDensity;
        return (int)(sp * scale + 0.5f);
         */
    }
}
